package com.mercury.share.controller;


import com.mercury.share.entity.ShareComments;
import com.mercury.share.service.ShareCommentsService;
import com.mercury.util.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @author tong
 * @since 2021-11-22
 */
@RestController
@RequestMapping("/share/comments")
public class ShareCommentsController {
    @Autowired
    private ShareCommentsService commentsService;

    /**
     * @date 2021/11/22 9:22
     * @params null
     * @return
     * @description 删除评论
    */
    @ApiOperation("删除评论")
    @DeleteMapping("comment/{id}")
    public R removeComment(@PathVariable int id) {
        boolean res = commentsService.removeById(id);
        if(res) return R.ok().message("删除评论成功");
        else return R.error();
    }

    /**
     * @date 2021/11/22 9:48
     * @params null
     * @return
     * @description 添加评论
    */
    @ApiOperation("添加评论")
    @PostMapping("comment")
    public R addComments(@RequestBody ShareComments shareComments) {
        shareComments.setDeleted(false);
        boolean save = commentsService.save(shareComments);
        if(save) return R.ok().message("发送评论成功");
        else return R.error().message("发送评论失败");

    }

}

